package com.zpark.web.config;

import com.zpark.web.filter.MyFilter02;
import com.zpark.web.listener.MyListener02;
import com.zpark.web.servlet.MyServlet02;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

/**
 * @PackageName: com.zpark.web.config
 * @ClassName: MyWebConfig
 * @Description:
 * @author: RZS
 * @date: 2022/9/27  10:35
 */
@Configuration
public class MyWebConfig {

    // 将MyServlet02添加到Spring容器中
    @Bean
    public ServletRegistrationBean servletRegistrationBean(){
        return new ServletRegistrationBean(new MyServlet02(), "/ms02.do");
    }

    // 将MyFilter02添加到Spring容器
    @Bean
    public FilterRegistrationBean filterRegistrationBean(){
        // 创建filter对象
        MyFilter02 filter02 = new MyFilter02();
        // 创建注册filter的bean
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(filter02);
        // 添加过滤路径
        filterRegistrationBean.setUrlPatterns(Arrays.asList("*.do"));

        return filterRegistrationBean;
    }

    // 将监听器添加到Spring容器中
    @Bean
    public ServletListenerRegistrationBean listenerRegistrationBean(){
        return new ServletListenerRegistrationBean(new MyListener02());
    }

}
